package com.logic.landseaserver.models.useranswer.ws;

import java.util.List;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.logic.common.enums.HttpCodeEnum;
import com.logic.common.util.CommonResult;
import com.logic.common.util.CommonResultMap;
import com.logic.landseaserver.common.exception.LandseaException;
import com.logic.landseaserver.common.util.LoggerHelper;
import com.logic.landseaserver.models.useranswer.bean.UserAnswerReq;
import com.logic.landseaserver.models.useranswer.bean.UserAnswerResp;
import com.logic.landseaserver.models.useranswer.service.UserAnswerService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@Path("/useranswer")
@Api(value = "用户答疑")
public class UserAnswerRest
{
    private static final Logger LOGGER = LoggerFactory.getLogger(UserAnswerRest.class);
    
    @Autowired
    private UserAnswerService userAnswerService;
    
    @POST
    @Path("/saveUserAnswer")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    @ApiOperation(value = "保存用户答疑信息")
    public Response saveUserAnswer(@ApiParam(value = "param", required = true) List<UserAnswerReq> userAnswerReqList)
    {
        CommonResultMap map = new CommonResultMap();
        try
        {              
            userAnswerService.saveUserAnswer(userAnswerReqList);  
            map.setResult(CommonResult.SUCCESS);
        }
        catch (LandseaException e)
        {
            LoggerHelper.handleException(LOGGER, "saveUserAnswer", e, map);
        }
        return Response.status(HttpCodeEnum.OK.getCode()).entity(map).build();
    }
    
    @POST
    @Path("/getUserAnswerList")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    @ApiOperation(value = "查询用户答疑信息列表")
    public Response getUserAnswerList()
    {
        CommonResultMap map = new CommonResultMap();
        try
        {
            List<UserAnswerResp> userAnswerRespList = userAnswerService.getUserAnswerList();
            map.setData(userAnswerRespList);
            map.setResult(CommonResult.SUCCESS);
        }
        catch (LandseaException e)
        {
            LoggerHelper.handleException(LOGGER, "getUserAnswerList", e, map);
        }
        return Response.status(HttpCodeEnum.OK.getCode()).entity(map).build();
    }
    
}
